//
//  Chats.h
//  SolarSeek
//
//  Created by Erick Fejta on 05/05/21.
//  Copyright 2005 __MyCompanyName__. All rights reserved.
//

#import <Cocoa/Cocoa.h>

#import "KVMutableSet.h"

#import "Peers.h"
#import "EnumTypes.h"

@interface Room : NSObject {
	NSString *name;
	unsigned countOfPeers;
	BOOL inside;
	BOOL joined;
}

- (id)initWithName:(NSString *)name count:(unsigned)count;
- (id)initWithName:(NSString *)name;
+ (id)roomNamed:(NSString *)name;

- (unsigned)countOfPeers;
- (void)setCountOfPeers:(unsigned)count;
- (BOOL)inside;
- (void)setInside:(BOOL)inside;
- (void)setJoined:(BOOL)joined;
- (BOOL)joined;

- (NSString *)name;

@end


@interface Statement : NSObject {
	NSString *statement;
	Peer *peer;
	NSDate *date;
}

- (id)initWithStatement:(NSString *)s peer:(Peer *)p date:(NSDate *)d;

+ (id)statement:(NSString *)s fromPeer:(Peer *)p;


- (NSDate *)date;
- (Peer *)peer;
- (NSString *)statement;
- (NSTimeInterval)timeElapsedTillNow;
@end


@interface Chat : NSObject {
	ChatType type;
	unsigned countOfStatementsNew;
	Statement *statementLast;
	NSMutableArray *statements;
	NSMutableArray *waiting;

	KVMutableSet *peers;
	KVMutableSet *peersJoined;
	BOOL managed;
	unsigned countOfStatementsMax;
}

- (id)init;
+ (id)chat;

- (KVMutableSet *)peers;
- (KVMutableSet *)peersJoined;

- (unsigned)countOfStatementsNew;
- (void)setCountOfStatementsNew:(unsigned)count;

- (unsigned)countOfStatements;
- (NSArray *)statements;

- (Statement *)statementLast;


- (void)setManaged:(BOOL)manage;
- (BOOL)isManaged;

- (void)setCountOfStatementsMax:(unsigned)max;
- (unsigned)countOfStatementsMax;

- (ChatType)type;
- (NSString *)name;

- (NSImage *)icon;


- (void)addStatement:(NSString *)statement fromPeer:(Peer *)peer;
- (void)trimToCountOfStatements:(unsigned)count;

- (void)joinPeer:(Peer *)peer;
- (void)partPeer:(Peer *)peer;


@end

@interface Chat (RoomOptions)
- (Room *)room;
- (Peer *)peerJoined;
- (Peer *)peerParted;
@end

@interface Chat (PrivateOptions)
- (Peer *)peer;
@end

@interface RoomChat : Chat {
	Room *room;
	Peer *peerJoined;
	Peer *peerParted;
}

- (id)initWithRoom:(Room *)room;
+ (id)chatWithRoom:(Room *)room;

@end

@interface PrivateChat : Chat {
	Peer *peer;
}

- (id)initWithPeer:(Peer *)peer;
+ (id)chatWithPeer:(Peer *)peer;

- (Peer *)peer;

@end